//
//  RecordTableViewCell.m
//  JiFengDaRen
//
//  Created by shouhan on 2018/6/8.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "RecordTableViewCell.h"
#import "SubModel.h"
#import "RecordModel.h"

@interface RecordTableViewCell()

@property (nonatomic, strong) UILabel *phoneLabel;

@property (nonatomic, strong) UILabel * type;

@property (nonatomic, strong) UILabel * tradeLabel;

@property (nonatomic, strong) UILabel * profitLabel;

@property (nonatomic, strong) UIView * line;

@end

@implementation RecordTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}


+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView
{
    static NSString * cellIndentfile = @"RecordTableViewCell";
    RecordTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[RecordTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)initUI{
    
    self.phoneLabel = [UILabel new];
    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.phoneLabel.font = KSHSystemFont(14);
    [self.contentView addSubview:self.phoneLabel];
    
    self.type = [UILabel new];
    self.type.textColor = [UIColor colorWithHexString:@"#333333"];
    self.type.font = KSHSystemFont(14);
    [self.contentView addSubview:self.type];
    
    self.tradeLabel = [UILabel new];
    self.tradeLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    self.tradeLabel.font = KSHSystemFont(14);
    self.tradeLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.tradeLabel];
    
    self.profitLabel = [UILabel new];
    self.profitLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    self.profitLabel.font = KSHSystemFont(14);
    self.profitLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.profitLabel];
    
    self.line = [UIView new];
    self.line.backgroundColor = [UIColor colorWithHexString:@"#E0E0E0"];
    [self.contentView addSubview:self.line];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    
    [@[self.phoneLabel,self.type] mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:5 leadSpacing:10 tailSpacing:10];
    
    [@[self.phoneLabel,self.type] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(__I6Width(16));
    }];
    
    [@[self.tradeLabel,self.profitLabel] mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:5 leadSpacing:10 tailSpacing:10];
    
    [@[self.tradeLabel,self.profitLabel] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-__I6Width(16));
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.contentView);
        make.height.mas_offset(.5);
    }];
    
}

- (void)setModel:(SubModel *)model{
    _model = model;
    
    self.phoneLabel.text = [Tool numberSuitScanf:model.phone];
    if (model.is_agent == YES) {
        self.type.text = @"代理商";
    }else{
        self.type.text = @"普通客户";
    }
    self.tradeLabel.text = [NSString stringWithFormat:@"交易:¥%@",model.money];
    self.profitLabel.text = [NSString stringWithFormat:@"分润:¥%@",model.commission];

}

@end

@interface DateTableViewCell()

@property (nonatomic, strong) UILabel *dateLabel;

@property (nonatomic, strong) UIImageView * arrow;

@property (nonatomic, strong) UIView * line;

@end

@implementation DateTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}


+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView
{
    static NSString * cellIndentfile = @"DateTableViewCell";
    DateTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[DateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)initUI{
    
    self.dateLabel = [UILabel new];
    self.dateLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.dateLabel.font = KSHSystemFont(14);
    [self.contentView addSubview:self.dateLabel];
    
    self.date = [UILabel new];
    self.date.textColor = [UIColor colorWithHexString:@"#666666"];
    self.date.font = KSHSystemFont(14);
    self.date.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.date];
    
    self.arrow = [UIImageView new];
    self.arrow.image = [UIImage imageNamed:@"jmarrow"];
    [self.contentView addSubview:self.arrow];
    
    self.line = [UIView new];
    self.line.backgroundColor = [UIColor colorWithHexString:@"#E0E0E0"];
    [self.contentView addSubview:self.line];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(__I6Width(16));
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-__I6Width(16));
    }];
    
    [self.date mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.arrow.mas_left).offset(-10);
        make.centerY.equalTo(self.contentView);
    }];
        
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.contentView);
        make.height.mas_offset(.5);
    }];
    
}

- (void)getCellIndex:(NSInteger)index{
    if (index == 1) {
        self.dateLabel.text = @"还款起始日期";
    }else{
        self.dateLabel.text = @"还款终止日期";
    }
}

@end

@interface SearchTableViewCell()

@property (nonatomic, strong) UILabel * dealLabel;

@property (nonatomic, strong) UILabel * profitLabel;

@property (nonatomic, strong) UIView * line;

@end

@implementation SearchTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}


+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView
{
    static NSString * cellIndentfile = @"SearchTableViewCell";
    SearchTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[SearchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)initUI{
    
    self.dealLabel = [UILabel new];
    self.dealLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.dealLabel.font = KSHSystemFont(14);
    self.dealLabel.text = @"交易:";
    [self.contentView addSubview:self.dealLabel];
    
    self.profitLabel = [UILabel new];
    self.profitLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.profitLabel.font = KSHSystemFont(14);
    self.profitLabel.text = @"分润:";
    [self.contentView addSubview:self.profitLabel];
    
    self.line = [UIView new];
    self.line.backgroundColor = [UIColor colorWithHexString:@"#E0E0E0"];
    [self.contentView addSubview:self.line];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.dealLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(__I6Width(16));
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.profitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dealLabel.mas_right).offset(__I6Width(15));
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.contentView);
        make.height.mas_offset(.5);
    }];
    
}

- (void)setModel:(RecordModel *)model{
    _model = model;
    if (model != nil) {
        self.dealLabel.text = [NSString stringWithFormat:@"交易:¥%@",model.money];
        self.profitLabel.text = [NSString stringWithFormat:@"分润:¥%@",model.commission];
    }

}
@end


